package com.jack.payment.service.basic;

import com.jack.payment.constant.ResultHintConstant;
import com.jack.payment.dao.payment.PaymentAttachDao;
import com.jack.payment.entity.common.BusinessException;
import com.jack.payment.entity.filter.PayFilter;
import com.jack.payment.entity.generate.payment.PaymentAttachModel;
import com.jack.payment.util.common.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PayAttachServiceImpl {
    private Logger log = LoggerFactory.getLogger(PayAttachServiceImpl.class);

    private final static String MQ_TABLE_NAME = "zlog_payment_mq";

    @Autowired
    private PaymentAttachDao paymentAttachDao;



    /**
     * 筛选出符合条件的支付信息总条数
     * @return
     */
    public Integer getFilterPayAttachCount(PayFilter.PayAttachFilter payAttachFilter) {
        return paymentAttachDao.getFilterPayAttachCount(payAttachFilter);
    }

    /**
     * 筛选出符合条件的支付信息列表
     * @param payAttachFilter
     * @return
     */
    public List<PaymentAttachModel> getFilterPayAttachList(PayFilter.PayAttachFilter payAttachFilter) throws BusinessException {
        List<PaymentAttachModel> resultAttachList = paymentAttachDao.getFilterPayAttachList(payAttachFilter);
        if (resultAttachList.isEmpty()) {
            log.warn("筛选支付数据为空");
            throw new BusinessException(ResultHintConstant.BASIC_DATA_DROP);
        }
        return resultAttachList;
    }

    /**
     * 获取指定的支付条件数据
     * @param orderNo
     * @return
     */
    public PaymentAttachModel getAppointPayAttachDetail(String orderNo) throws BusinessException {
        if (StringUtil.isEmail(orderNo)) {
            log.warn("重要查询的订单号不能为空");
            throw new BusinessException(ResultHintConstant.DATA_NOT_EXIST);
        }
        PaymentAttachModel paymentAttachModel = paymentAttachDao.getAppointPayAttach(orderNo);
        if (paymentAttachModel == null) {
            log.warn("查询的订单数据不存在");
            throw new BusinessException(ResultHintConstant.BASIC_DATA_DROP);
        }
        return paymentAttachModel;
    }
}
